import { Module } from "@nestjs/common";
import { ServeStaticModule } from "@nestjs/serve-static"; //静态资源
import { TypeOrmModule } from "@nestjs/typeorm";
import { WebsocketModule } from "./websockets/websocket.module";
import { join } from "path";
import { UserModule } from "./module/user/user.module";
import { AuthModule } from "./auth/auth.module";
import { JwtModule } from "@nestjs/jwt";
import { serverConfig, dbConfig } from "./common/config";
import { APP_GUARD } from "@nestjs/core";
import { AuthGuard } from "./common/auth.guard";
import { UploadModule } from "./module/upload/upload.module";
import { ConfigModule } from "./module/config/config.module";
@Module({
  imports: [
    // 静态资源访问
    ServeStaticModule.forRoot({
      rootPath: join(__dirname, ".", "html"),
      serveRoot: "/html",
    }),
    // 静态资源访问 - 上传的文件地址访问
    ServeStaticModule.forRoot({
      rootPath: join(__dirname, ".", "public"),
      serveRoot: "/public",
      serveStaticOptions: {
        dotfiles: "ignore",
        fallthrough: true,
      },
    }),
    // 加载连接数据库
    TypeOrmModule.forRoot(dbConfig[dbConfig.systemDB]),
    WebsocketModule,
    UserModule,
    AuthModule,
    JwtModule.register({
      global: true, // 设置为全局可用
      secret: serverConfig.JWT_SECRET,
      signOptions: {
        expiresIn: serverConfig.JWT_EXPIRES,
      },
    }),
    //模块部分
    UploadModule,
    ConfigModule,
  ],
  controllers: [],
  providers: [
    {
      provide: APP_GUARD,
      useClass: AuthGuard,
    },
  ],
})
export class AppModule {}
